package com.sam.mooc;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by samwang on 2017/12/3.
 */
public class TestFrame {
    private JPanel panel1;
    private JTextField textField1;
    private JTextField textField2;
    private JButton btn;
    private JLabel jlabelResult;

    public TestFrame() {
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int height = Integer.valueOf(textField1.getText());
                int weight = Integer.valueOf(textField2.getText());
                double bmi = ((float) weight) / Math.sqrt((float) height / 100);
                String result = String.format("BMI:%.2f,偏重：%b",bmi,bmi>24);
                jlabelResult.setText(result);

                System.out.println(result);
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("TestFrame");
        frame.setContentPane(new TestFrame().panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.pack();
        frame.setVisible(true);
        frame.setSize(420,150);
    }
}
